package org.jeecg.codegeneweb.domian.column;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;
import org.hibernate.validator.constraints.Length;
import org.jeecg.common.util.oConvertUtils;


@Data
@SuperBuilder
@AllArgsConstructor
@NoArgsConstructor
public class DbVo {
    @Length(min=2,max=50)
    private String dbFieldName;//product_name，页面上的名称  数据库属性-字段名称
    @Length(min=2,max=50)
    private String dbFieldTxt;//产品名字                    数据库属性-字段备注
    //private String dbFieldNameOld;//空
    private Integer dbIsKey;//1 代表是，0代表不是             数据库属性-主键
    private Integer dbIsNull=1;//1,0,是否为空                 数据库属性- 允许空值,1 代表允许空
    @Length(min=2,max=50)
    private String  dbType;//String,Date                    数据库属性-字段类型 String，Integer，Double，Date，DateTime，BigDecimal，Text，Blob
    private Integer dbLength;//32                          数据库属性-字段长度
    private Integer dbPointLength;//0                      数据库属性-小数点
    private String dbDefaultVal;//":"null",                数据库属性-默认值

    public String getDbFieldName() {
        return dbFieldName;
    }

    public void setDbFieldName(String dbFieldName) {
        this.dbFieldName = dbFieldName;
    }

    public String getDbFieldTxt() {
        return dbFieldTxt;
    }

    public void setDbFieldTxt(String dbFieldTxt) {
        this.dbFieldTxt = dbFieldTxt;
    }

   /* public String getDbFieldNameOld() {
        return dbFieldNameOld;
    }

    public void setDbFieldNameOld(String dbFieldNameOld) {
        this.dbFieldNameOld = dbFieldNameOld;
    }*/

    public Integer getDbIsKey() {
        return dbIsKey;
    }

    public void setDbIsKey(Integer dbIsKey) {
        this.dbIsKey = dbIsKey;
    }

    public Integer getDbIsNull() {
        return dbIsNull;
    }

    public void setDbIsNull(Integer dbIsNull) {
        this.dbIsNull = dbIsNull;
    }

    public String getDbType() {
        return dbType;
    }

    public void setDbType(String dbType) {
        this.dbType = dbType;
    }

    public Integer getDbLength() {
        return dbLength;
    }

    public void setDbLength(Integer dbLength) {
        this.dbLength = dbLength;
    }

    public Integer getDbPointLength() {
        return dbPointLength;
    }

    public void setDbPointLength(Integer dbPointLength) {
        this.dbPointLength = dbPointLength;
    }

    public String getDbDefaultVal() {
        return dbDefaultVal;
    }

    public void setDbDefaultVal(String dbDefaultVal) {
        this.dbDefaultVal = dbDefaultVal;
    }

    public ValidateVo getValidateVo() {
        return validateVo;
    }

    public void setValidateVo(ValidateVo validateVo) {
        this.validateVo = validateVo;
    }
    public String getFieldName(){
       return oConvertUtils.camelName(getDbFieldName());
    }
    public String getFieldType(){
        return getWrapper(getDbType());
    }
    /*public String getNullable(){

        if (getDbIsNull() != 0 && !"*".equals(validateVo.getFieldValidType()) && !"1".equals(validateVo.getFieldMustInput())) {
            return  "Y";
        } else {
            return "N";
        }

    }*/

    //aux getNullable的判断
    private ValidateVo validateVo;

    public String getWrapper(String fieldType) {
        fieldType = fieldType.toLowerCase();
        if (fieldType.indexOf("int") >= 0) {
            return "java.lang.Integer";
        } else if (fieldType.indexOf("double") >= 0) {
            return "java.lang.Double";
        } else if (fieldType.indexOf("decimal") >= 0) {
            return "java.math.BigDecimal";
        } else {
            return fieldType.indexOf("date") >= 0 ? "java.util.Date" : "java.lang.String";
        }
    }
}
